package com.example.administrator.szb.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.bean.ProjectDetail;

import java.util.HashMap;
import java.util.List;

/**
 * Created by stone on 2018/1/17.
 */

public class XMAdapter extends android.widget.BaseAdapter {
    private Context context;
    private List<ProjectDetail> list;
    private LayoutInflater inflater;
    private int type;
    public XMAdapter(Context context, List<ProjectDetail> list,int types) {
        this.context = context;
        this.list = list;
        this.type=types;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public ProjectDetail getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.item_xiangmu,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        ProjectDetail dataBean = getItem(position);
        holder.reset();
        boolean isSuPei = false;
        if (isSuPei){
            holder.iv_supei.setVisibility(View.VISIBLE);
            holder.ll_bottom.setVisibility(View.VISIBLE);
            holder.tips_content.setText(dataBean.getCreate_time());

        }else {
            if (type==2){
                holder.ll_bottom.setVisibility(View.VISIBLE);
                holder.tips.setText("申请人：");
                holder.tips_content.setText(dataBean.getName());
            }
        }

        holder.tv_title.setText(dataBean.getBusinessName());
        holder.tv_status.setText((String)dataBean.getStatus());
        HashMap<Integer, ProjectDetail.YWInfoData> map = (HashMap<Integer, ProjectDetail.YWInfoData>) dataBean.getIndentInfo();
        String info = "";
        for (int i = 0; i < dataBean.getBusformId().size(); i++) {
            int key = dataBean.getBusformId().get(i);
            switch (i){
                case 0:
                    holder.tv_1.setText(map.get(key).getValueName());
                    holder.tv_1_content.setText(map.get(key).getKeyName());
                    holder.tv_1.setVisibility(View.VISIBLE);
                    holder.tv_1_content.setVisibility(View.VISIBLE);
                    break;
                case 1:

                    holder.tv_2.setText(map.get(key).getValueName());
                    holder.tv_2_content.setText(map.get(key).getKeyName());
                    holder.tv_2.setVisibility(View.VISIBLE);
                    holder.tv_2_content.setVisibility(View.VISIBLE);
                    break;
                case 2:

                    holder.tv_3.setText(map.get(key).getValueName());
                    holder.tv_3_content.setText(map.get(key).getKeyName());
                    holder.tv_3.setVisibility(View.VISIBLE);
                    holder.tv_3_content.setVisibility(View.VISIBLE);
                    break;
            }
            //info = info + map.get(dataBean.getBusformId().get(i)).getKeyName() +":"+ map.get(dataBean.getBusformId().get(i)).getValueName() +"     ";
        }

        if (dataBean.getBusformId().size() == 0){
            holder.center_content.setText(dataBean.getContent());
            holder.ll_center2.setVisibility(View.VISIBLE);
        }else {
            holder.ll_center1.setVisibility(View.VISIBLE);

        }
        int status = dataBean.getStatusType();
        if (status==1||status==3||status==5||status==6||status==7||status==9){
            holder.tv_status.setBackgroundColor(Color.parseColor("#D7EBFA"));
            holder.tv_status.setTextColor(Color.parseColor("#0096FF"));
        }
        return convertView;
    }

    class ViewHolder{
        private LinearLayout checkBox_ll,ll_bottom;
        private ImageView iv_supei;
        private TextView tv_title;
        private TextView tv_status;
        private LinearLayout ll_center2;
        private TextView center_content;
        private LinearLayout ll_center1;
        private TextView tv_1;
        private TextView tv_2;
        private TextView tv_3;
        private TextView tv_1_content;
        private TextView tv_2_content;
        private TextView tv_3_content;
        private ImageView clock;
        private TextView tips;
        private TextView tips_content;




        public ViewHolder(View view) {
            checkBox_ll = (LinearLayout) view.findViewById(R.id.checkBox_ll);
            iv_supei = (ImageView) view.findViewById(R.id.iv_supei);
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_status = (TextView) view.findViewById(R.id.tv_status);
            ll_center2 = (LinearLayout) view.findViewById(R.id.ll_center2);
            center_content = (TextView) view.findViewById(R.id.center_content);
            ll_center1 = (LinearLayout) view.findViewById(R.id.ll_center1);
            tv_1 = (TextView) view.findViewById(R.id.tv_1);
            tv_2 = (TextView) view.findViewById(R.id.tv_2);
            tv_3 = (TextView) view.findViewById(R.id.tv_3);
            tv_1_content = (TextView) view.findViewById(R.id.tv_1_content);
            tv_2_content = (TextView) view.findViewById(R.id.tv_2_content);
            tv_3_content = (TextView) view.findViewById(R.id.tv_3_content);
            clock = (ImageView) view.findViewById(R.id.clock);
            tips = (TextView) view.findViewById(R.id.tips);
            tips_content = (TextView) view.findViewById(R.id.tips_content);
            ll_bottom = view.findViewById(R.id.ll_bottom);
        }
        private void reset(){
            iv_supei.setVisibility(View.GONE);
            ll_center1.setVisibility(View.GONE);
            ll_center2.setVisibility(View.GONE);
            clock.setVisibility(View.GONE);
            ll_bottom.setVisibility(View.GONE);
            tv_1.setVisibility(View.GONE);
            tv_1_content.setVisibility(View.GONE);
            tv_2.setVisibility(View.GONE);
            tv_2_content.setVisibility(View.GONE);
            tv_3.setVisibility(View.GONE);
            tv_3_content.setVisibility(View.GONE);
            tv_status.setBackgroundColor(Color.parseColor("#EAEAEA"));
            tv_status.setTextColor(Color.parseColor("#c9c9c9"));
            tips.setText("项目结束时间：");
        }
    }
}
